package net.livingflow.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * @author xueqiang.mi
 * @since 2010-11-26
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Pack implements Serializable {
	private static final long serialVersionUID = 2277915403895696029L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;
	@Persistent
	private String name;
	@Persistent
	private String type = "0";
	@Persistent
	private int rating = 0;
	@Persistent
	private Date crtDate;
	@Persistent
	private Date modDate;
	@Persistent
	private String owner;
	@Persistent
	private Set<String> users;

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pack other = (Pack) obj;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}

	public Date getCrtDate() {
		return crtDate;
	}

	public Long getId() {
		return id;
	}

	public Date getModDate() {
		return modDate;
	}

	public String getName() {
		return name;
	}

	public String getOwner() {
		return owner;
	}

	public int getRating() {
		return rating;
	}

	public String getType() {
		return type;
	}

	public Set<String> getUsers() {
		if (users == null) {
			users = new HashSet<String>();
		}
		return users;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	public void setCrtDate(Date crtDate) {
		this.crtDate = crtDate;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setModDate(Date modDate) {
		this.modDate = modDate;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public void setRating(int rating) {
		this.rating = rating;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setUsers(Set<String> users) {
		this.users = users;
	}

	@Override
	public String toString() {
		return "FlowPackage [id=" + id + ", name=" + name + ", rating=" + rating + "]";
	}
}
